package centerberg.engine;



public class SoundEngine {
    public SoundEngine() {
    }
    /**
     * 
     * @param sound    The name of the sound to be played
     * @param duration The duration to play the sound for, 0 plays full clip
     * @param volume   The volume to play the sound at 0 is original volume
     * @param balance  The balance to play the sound at, 0 is original value
     */
    public void playSound(final String sound,final int duration, final float volume, final float balance) {
        final SoundLoader loader = Engine.getInstance().resourceManager.soundLoader;
        
        if(loader.getSound(sound) == null)
            throw new IllegalArgumentException("Sound does not exist");
        new Thread( 
            new Runnable() {
                public void run() {
                    Sound s = loader.getSound(sound);
                    if(s.isPlaying()) {
                        s = new Sound(s.getFile());
                    }
                    s.play(duration, volume, balance);
                }
            }
        ).start();
    }
}
